from core.support import set_cutscene, get_game
from core.basehandler import BaseHandler
from core.room import Room
#from items.oilcan import OilCan
#from items.lamp import Lamp
from core.action import Action


class GradLounge(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        # add inventory items
        # self.add_item(Lamp())
        # self.add_item(OilCan())
        
        # build list of actions
        self.locked = True
        self.solving = True
        self.add_action(GoDeanOffice)
        self.add_action(GoCouncilRoom)
        self.add_action(GoBallroom)
        self.add_action(AnswerA)
        self.add_action(AnswerB)
        self.add_action(AnswerC)

    
    # return description of room.
    def get_description(self):
        game = get_game()
        if self.locked:
            if ('BUid' in game.get_player().inventory):
                desc = "Swipe your ID to enter the Grad Lounge."
            else:
                desc = "You need your BU ID to enter the Grad Lounge. Find your ID."
        elif not self.solving:
            desc = "Good job! Your smartphone just reminded you that today is the last day to buy tickets for the Boat Cruise.  Perhaps that's what Dean Freeman is doing... "
        else:
            desc = "OH NO! there's a silly undergrad hanging out in the grad lounge.  In order to have a fellow classmate give you a clue about where Dean Freeman is, you need to chase out the silly undergrad... Which person do you want to yell at?"
        return desc
    
    # return image of room
    def get_image(self):
        if self.locked:
            return 'gradlocked.jpg'
        elif self.solving:
            return 'grad_faces.jpg'
        return 'gradlounge.jpg'


class GradLoungeHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return GradLounge

# define actions for this room

class GoDeanOffice(Action):
    def __init__(self):
        Action.__init__(self, "GoDeanOffice")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to Dean Freeman's Office"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        game.get_room('gradlounge', GradLounge).locked = True
        game.get_room('gradlounge', GradLounge).inventory.clear()
        #while (len(game.get_room('gradlounge', GradLounge).inventory) > 0):
            #game.get_room('gradlounge', GradLounge).inventory.pop()
        return 'deanoffice'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

    #def is_enabled(self):
      #  game = get_game()
      #  if game.history[-1].solving:
       #     return False
       # else:
       #     return True

class GoCouncilRoom(Action):
    def __init__(self):
        Action.__init__(self, "GoCouncilRoom")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to the Council Room"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        game.get_room('gradlounge', GradLounge).locked = True
        game.get_room('gradlounge', GradLounge).inventory.clear()
        #while (len(game.get_room('gradlounge', GradLounge).inventory) > 0):
            #game.get_room('gradlounge', GradLounge).inventory.pop()
        return 'councilroom'
    
               
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
        
    #def is_enabled(self):
        #game = get_game()
        #if game.history[-1].solving:
            #return False
        #else:
            #return True
    
class GoBallroom(Action):
    def __init__(self):
        Action.__init__(self, "GoBallroom")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go to the Ballroom"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        game.get_room('gradlounge', GradLounge).locked = True
        game.get_room('gradlounge', GradLounge).inventory.clear()
        #while (len(game.get_room('gradlounge', GradLounge).inventory) > 0):
            #game.get_room('gradlounge', GradLounge).inventory.pop()
        return 'ballroom'
    
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    #def is_enabled(self):
        #game = get_game()
        #if game.history[-1].solving:
          #  return False
        #else:
           # return True
    
class AnswerA(Action):
    def __init__(self):
        Action.__init__(self, "AnswerA")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Answer: A"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'gradlounge'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"    
    
    def do_action(self,game,room,request):
        set_cutscene("Don't try to kick out the nice PEMBA student, fool!!")
        return
        
    def is_enabled(self):
        game = get_game()
        if (not game.history[-1].locked) & game.history[-1].solving:
                return True
        else:
            return False
        
class AnswerB(Action):
    def __init__(self):
        Action.__init__(self, "AnswerB")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Answer: B"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'gradlounge'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"    
    
    def do_action(self,game,room,request):
        set_cutscene("You are mean!  She's in Cohort A, fool!  ")
        return
        
    def is_enabled(self):
        game = get_game()
        if (not game.history[-1].locked) & game.history[-1].solving:
                return True
        else:
            return False

class AnswerC(Action):
    def __init__(self):
        Action.__init__(self, "AnswerC")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Answer: C"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'gradlounge'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get" 
    
    def do_action(self,game,room,request):
#        set_cutscene("Good job!  Your smartphone just reminded you that today is the last day to buy tickets for the Boat Cruise.  Perhaps that's what Dean Freeman is doing...")
        room.solving = False
        return
    
    def is_enabled(self):
        game = get_game()
        if (not game.history[-1].locked) & game.history[-1].solving:
                return True
        else:
            return False